package com.fr.chart.core.glyph;

import com.fr.base.background.GradientBackground;
import com.fr.base.core.IteratorChain;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.core.util.vt.VT4FR;
import com.fr.base.core.util.vt.VT4FR.FUNC;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.GeneralInfo;
import com.fr.chart.LineStyleInfo;
import com.fr.chart.axis.SeriesAttrBackground;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.FoldLine;
import com.fr.chart.core.Glyph;
import com.fr.chart.plot.CustomAttr;
import com.fr.chart.plot.DataPoint;
import com.fr.chart.plot.DataSeries;
import com.fr.chart.plot.MarkerGlyph;
import com.fr.chart.plot.SeriesAttr;
import com.fr.chart.plot.SeriesCollection;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Arc2D.Double;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.geom.Rectangle2D.Double;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class CustomPlotGlyph extends CategoryPlotGlyph
{
  private static final long serialVersionUID = -717908304255012814L;
  public static final String XML_TAG = "CustomPlotGlyph";
  private boolean hasSecondValueAxis = false;
  private ValueAxisGlyph secondValueAxisGlyph;
  private boolean isSimulation3D = true;
  private double seriesOverlapPercent = -0.15D;
  private double categoryIntervalPercent = 1.0D;
  private boolean isShowLine = true;
  private boolean isShowMarker = true;
  private boolean isLineNullValueBreak = true;
  private boolean isAreaNullValueBreak = true;

  public void layoutAxisGlyph()
  {
    Rectangle2D localRectangle2D = getBounds();
    if ((this.hasSecondValueAxis) && (this.secondValueAxisGlyph != null))
      this.secondValueAxisGlyph.dealPlotBoundsWithAxisLabel(localRectangle2D);
    this.categoryAxisGlyph.dealPlotBoundsWithAxisLabel(localRectangle2D);
    this.valueAxisGlyph.dealPlotBoundsWithAxisLabel(localRectangle2D);
    this.categoryAxisGlyph.calculateAxisGlyph(localRectangle2D);
    this.valueAxisGlyph.calculateAxisGlyph(localRectangle2D);
    if ((this.hasSecondValueAxis) && (this.secondValueAxisGlyph != null))
      this.secondValueAxisGlyph.calculateAxisGlyph(localRectangle2D);
    setBounds(localRectangle2D);
  }

  public void layoutDataSeriesGlyph()
  {
    if (!(VT4FR.ADVANCED_CHART.support()))
      return;
    int i = 0;
    for (int j = 0; j < getSeriesSize(); ++j)
    {
      CustomAttr localCustomAttr1 = (CustomAttr)getSeriesCollection().getSeriesAttr(j);
      int l = localCustomAttr1.getRenderer();
      if (l == 1)
        ++i;
    }
    j = 0;
    for (int k = 0; k < getSeriesSize(); ++k)
    {
      GeneralPath localGeneralPath;
      Object localObject;
      float f3;
      float f4;
      int i8;
      DataSeries localDataSeries = getSeries(k);
      int i1 = 0;
      for (int i2 = 0; i2 < localDataSeries.getDataPointCount(); ++i2)
        if (!(localDataSeries.getDataPoint(i2).isValueIsNull()))
          ++i1;
      double[] arrayOfDouble1 = new double[i1];
      double[] arrayOfDouble2 = new double[i1];
      i1 = 0;
      CustomAttr localCustomAttr2 = (CustomAttr)getSeriesCollection().getSeriesAttr(k);
      int i3 = localCustomAttr2.getRenderer();
      String str = localCustomAttr2.getAxisPosition();
      ValueAxisGlyph localValueAxisGlyph = (str.equals("RIGHT")) ? getSecondValueAxisGlyph() : getValueAxisGlyph();
      if (i3 == 1)
      {
        for (int i4 = 0; i4 < localDataSeries.getDataPointCount(); ++i4)
        {
          localObject = localDataSeries.getDataPoint(i4);
          if (((DataPoint)localObject).isValueIsNull())
            break label421:
          Bar2DPlotGlyph localBar2DPlotGlyph = new Bar2DPlotGlyph();
          ShapeGlyph localShapeGlyph = new ShapeGlyph(localBar2DPlotGlyph.getBarShape4CustomPlot(k, i4, getCategoryAxisGlyph(), localValueAxisGlyph, this, i, j));
          ((DataPoint)localObject).setDrawImpl(localShapeGlyph);
          localShapeGlyph.getInfo().dealCondition(getSeriesCollection(), k);
          if ((isSimulation3D()) && (getSeriesCollection().getSeriesAttr(k).isContains(new SeriesAttrBackground()) == null))
          {
            Color localColor = com.fr.chart.core.ChartCoreConstants.CHART_COLOR_ARRAY[(k % com.fr.chart.core.ChartCoreConstants.CHART_COLOR_ARRAY.length)];
            localShapeGlyph.getInfo().setBackground(new GradientBackground(localColor.brighter(), localColor, GradientBackground.TOP2BOTTOM));
          }
          double d1 = getDataPointPercentValue(k, i4);
          Rectangle2D localRectangle2D = (Rectangle2D)localShapeGlyph.getShape();
          if (d1 > 0.0D)
          {
            arrayOfDouble1[i1] = localRectangle2D.getCenterX();
            arrayOfDouble2[i1] = localRectangle2D.getY();
          }
          else
          {
            arrayOfDouble1[i1] = localRectangle2D.getCenterX();
            arrayOfDouble2[i1] = (localRectangle2D.getY() + localRectangle2D.getHeight());
          }
          ++i1;
          dealDataPointLabelBounds((DataPoint)localObject, k);
        }
        ++j;
      }
      if (i3 == 4)
      {
        localGeneralPath = new GeneralPath(1);
        localObject = new ShapeGlyph(localGeneralPath);
        localDataSeries.setDrawImpl((Glyph)localObject);
        ((ShapeGlyph)localObject).getInfo().dealCondition(getSeriesCollection(), k);
        float f1 = (float)getCategoryAxisGlyph().getPoint2DCateAxis(0.0D, 0.0D).getX();
        float f2 = (float)localValueAxisGlyph.getPoint2D(localValueAxisGlyph.getCrossValue()).getY();
        f3 = (float)localValueAxisGlyph.getPoint2D(0.0D).getY();
        f4 = (float)getCategoryAxisGlyph().getUnitLen();
        localGeneralPath.moveTo(f1 + f4 / 2.0F, f3);
        for (int i7 = 0; i7 < localDataSeries.getDataPointCount(); ++i7)
        {
          DataPoint localDataPoint2 = localDataSeries.getDataPoint(i7);
          if (localDataPoint2.isValueIsNull())
          {
            if (isAreaNullValueBreak())
            {
              if (i7 > 0)
                localGeneralPath.lineTo((float)(getCategoryAxisGlyph().getPoint2DCateAxis(i7 - 1, 0.0D).getX() + f4 / 2.0F), f3);
              localGeneralPath.lineTo((float)(getCategoryAxisGlyph().getPoint2DCateAxis(i7, 0.0D).getX() + f4 / 2.0F), f3);
              if (i7 < localDataSeries.getDataPointCount())
                localGeneralPath.lineTo((float)(getCategoryAxisGlyph().getPoint2DCateAxis(i7 + 1, 0.0D).getX() + f4 / 2.0F), f3);
            }
          }
          else
          {
            double d3 = getDataPointPercentValue(k, i7);
            f1 = (float)(getCategoryAxisGlyph().getPoint2DCateAxis(i7, 0.0D).getX() + f4 / 2.0F);
            f2 = (float)localValueAxisGlyph.getPoint2D(d3).getY();
            arrayOfDouble1[i1] = f1;
            arrayOfDouble2[i1] = f2;
            ++i1;
            localGeneralPath.lineTo(f1, f2);
            localDataPoint2.setShape(new Arc2D.Double(f1 - 3.0F, f2 - 3.0F, 6.0D, 6.0D, 0.0D, 360.0D, 2));
            dealDataPointLabelBounds(localDataPoint2, k);
          }
        }
        for (i8 = localDataSeries.getDataPointCount() - 1; i8 >= 0; --i8)
        {
          if (localDataSeries.getDataPoint(i8).isValueIsNull())
            break label866:
          localGeneralPath.lineTo((float)(getCategoryAxisGlyph().getPoint2DCateAxis(i8, 0.0D).getX() + f4 / 2.0F), f3);
        }
      }
      if (i3 == 2)
      {
        localGeneralPath = new GeneralPath(1);
        int i5 = 1;
        for (int i6 = 0; i6 < localDataSeries.getDataPointCount(); ++i6)
        {
          DataPoint localDataPoint1 = localDataSeries.getDataPoint(i6);
          if (localDataPoint1.isValueIsNull())
          {
            if (isLineNullValueBreak())
              i5 = 1;
          }
          else
          {
            double d2 = getDataPointPercentValue(k, i6);
            float f5 = (float)getCategoryAxisGlyph().getPoint2DCateAxis(i6, 0.5D).getX();
            float f6 = (float)localValueAxisGlyph.getBounds().getY() + (float)localValueAxisGlyph.getPoint2D(d2).getY();
            if (i5 != 0)
            {
              localGeneralPath.moveTo(f5, f6);
              i5 = 0;
            }
            else
            {
              localGeneralPath.lineTo(f5, f6);
            }
            arrayOfDouble1[i1] = f5;
            arrayOfDouble2[i1] = f6;
            ++i1;
            if (isShowMarker())
            {
              MarkerGlyph localMarkerGlyph = new MarkerGlyph();
              localMarkerGlyph.dealCondition4Line(getSeriesCollection(), k);
              localMarkerGlyph.setShape(new Rectangle2D.Double(f5 - 5.0F, f6 - 5.0F, 10.0D, 10.0D));
              localDataPoint1.setDrawImpl(localMarkerGlyph);
            }
            else
            {
              localDataPoint1.setShape(new Rectangle2D.Double(f5 - 5.0F, f6 - 5.0F, 10.0D, 10.0D));
            }
            dealDataPointLabelBounds(localDataPoint1, k);
          }
        }
        if (isShowLine())
        {
          FoldLine localFoldLine = new FoldLine(localGeneralPath);
          localDataSeries.setDrawImpl(localFoldLine);
          localFoldLine.getLineStyleInfo().dealCondition(getSeriesCollection(), k);
        }
      }
      trendLineFitting(arrayOfDouble1, arrayOfDouble2, k);
    }
    label421: label866: return;
  }

  public Iterator selectableChildren()
  {
    ArrayList localArrayList = new ArrayList();
    if ((this.hasSecondValueAxis) && (this.secondValueAxisGlyph != null))
      localArrayList.add(this.secondValueAxisGlyph);
    return new IteratorChain(new Iterator[] { super.selectableChildren(), localArrayList.iterator() });
  }

  public void draw(Graphics paramGraphics)
  {
    drawInfo(paramGraphics);
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    localGraphics2D.translate(getBounds().getX(), getBounds().getY());
    if ((this.hasSecondValueAxis) && (this.secondValueAxisGlyph != null))
      this.secondValueAxisGlyph.draw(localGraphics2D);
    localGraphics2D.translate(-getBounds().getX(), -getBounds().getY());
    super.draw(localGraphics2D);
  }

  public void setHasSecondValueAxis(boolean paramBoolean)
  {
    this.hasSecondValueAxis = paramBoolean;
  }

  public boolean getHasSecondValueAxis()
  {
    return this.hasSecondValueAxis;
  }

  public void setSecondValueAxisGlyph(ValueAxisGlyph paramValueAxisGlyph)
  {
    this.secondValueAxisGlyph = paramValueAxisGlyph;
  }

  public ValueAxisGlyph getSecondValueAxisGlyph()
  {
    return this.secondValueAxisGlyph;
  }

  public void setSimulation3D(boolean paramBoolean)
  {
    this.isSimulation3D = paramBoolean;
  }

  public boolean isSimulation3D()
  {
    return this.isSimulation3D;
  }

  public void setSeriesOverlapPercent(double paramDouble)
  {
    this.seriesOverlapPercent = paramDouble;
  }

  public double getSeriesOverlapPercent()
  {
    return this.seriesOverlapPercent;
  }

  public void setCategoryIntervalPercent(double paramDouble)
  {
    this.categoryIntervalPercent = paramDouble;
  }

  public double getCategoryIntervalPercent()
  {
    return this.categoryIntervalPercent;
  }

  public void setShowLine(boolean paramBoolean)
  {
    this.isShowLine = paramBoolean;
  }

  public boolean isShowLine()
  {
    return this.isShowLine;
  }

  public void setShowMarker(boolean paramBoolean)
  {
    this.isShowMarker = paramBoolean;
  }

  public boolean isShowMarker()
  {
    return this.isShowMarker;
  }

  public void setLineNullValueBreak(boolean paramBoolean)
  {
    this.isLineNullValueBreak = paramBoolean;
  }

  public boolean isLineNullValueBreak()
  {
    return this.isLineNullValueBreak;
  }

  public void setAreaNullValueBreak(boolean paramBoolean)
  {
    this.isAreaNullValueBreak = paramBoolean;
  }

  public boolean isAreaNullValueBreak()
  {
    return this.isAreaNullValueBreak;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("ValueAxisGlyph"))
      {
        this.secondValueAxisGlyph = ((ValueAxisGlyph)paramXMLableReader.readXMLObject(new ValueAxisGlyph()));
      }
      else if ("Attr".equals(str1))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("value")) != null)
          this.hasSecondValueAxis = Boolean.valueOf(str2).booleanValue();
        if ((str2 = paramXMLableReader.getAttr("isShowLine")) != null)
          this.isShowLine = Boolean.valueOf(str2).booleanValue();
        if ((str2 = paramXMLableReader.getAttr("isShowMarker")) != null)
          this.isShowMarker = Boolean.valueOf(str2).booleanValue();
        if ((str2 = paramXMLableReader.getAttr("isAreaNullValueBreak")) != null)
          this.isAreaNullValueBreak = Boolean.valueOf(str2).booleanValue();
        if ((str2 = paramXMLableReader.getAttr("isLineNullValueBreak")) != null)
          this.isLineNullValueBreak = Boolean.valueOf(str2).booleanValue();
        if ((str2 = paramXMLableReader.getAttr("categoryIntervalPercent")) != null)
          this.categoryIntervalPercent = Double.valueOf(str2).doubleValue();
        if ((str2 = paramXMLableReader.getAttr("seriesOverlapPercent")) != null)
          this.seriesOverlapPercent = Double.valueOf(str2).doubleValue();
        if ((str2 = paramXMLableReader.getAttr("isSimulation3D")) != null)
          this.isSimulation3D = Boolean.valueOf(str2).booleanValue();
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("CustomPlotGlyph");
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("Attr").attr("value", this.hasSecondValueAxis).attr("isShowLine", this.isShowLine).attr("isShowMarker", this.isShowMarker).attr("isLineNullValueBreak", this.isLineNullValueBreak).attr("isAreaNullValueBreak", this.isAreaNullValueBreak).attr("seriesOverlapPercent", this.seriesOverlapPercent).attr("categoryIntervalPercent", this.categoryIntervalPercent).attr("isSimulation3D", this.isSimulation3D).end();
    if (this.secondValueAxisGlyph != null)
      this.secondValueAxisGlyph.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof CustomPlotGlyph))
      return false;
    CustomPlotGlyph localCustomPlotGlyph = (CustomPlotGlyph)paramObject;
    if (!(super.equals(localCustomPlotGlyph)))
      return false;
    if ((localCustomPlotGlyph.hasSecondValueAxis != this.hasSecondValueAxis) || (localCustomPlotGlyph.isAreaNullValueBreak != this.isAreaNullValueBreak) || (localCustomPlotGlyph.isLineNullValueBreak != this.isLineNullValueBreak) || (localCustomPlotGlyph.isShowLine != this.isShowLine) || (localCustomPlotGlyph.isShowMarker != this.isShowMarker) || (localCustomPlotGlyph.seriesOverlapPercent != this.seriesOverlapPercent) || (localCustomPlotGlyph.categoryIntervalPercent != this.categoryIntervalPercent) || (localCustomPlotGlyph.isSimulation3D != this.isSimulation3D))
      return false;
    return (Equals.equals(localCustomPlotGlyph.secondValueAxisGlyph, this.secondValueAxisGlyph));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    CustomPlotGlyph localCustomPlotGlyph = (CustomPlotGlyph)super.clone();
    if (this.valueAxisGlyph != null)
      localCustomPlotGlyph.valueAxisGlyph = ((ValueAxisGlyph)this.valueAxisGlyph.clone());
    return localCustomPlotGlyph;
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = super.toJSONObject();
    localJSONObject.put("hasSecondValueAxis", this.hasSecondValueAxis);
    if (this.secondValueAxisGlyph != null)
      localJSONObject.put("secondValueAxisGlyph", this.secondValueAxisGlyph.toJSONObject());
    localJSONObject.put("isSimulation3D", this.isSimulation3D);
    localJSONObject.put("seriesOverlapPercent", this.seriesOverlapPercent);
    localJSONObject.put("categoryIntervalPercent", this.categoryIntervalPercent);
    localJSONObject.put("isShowLine", this.isShowLine);
    localJSONObject.put("isShowMarker", this.isShowMarker);
    localJSONObject.put("isLineNullValueBreak", this.isLineNullValueBreak);
    localJSONObject.put("isAreaNullValueBreak", this.isAreaNullValueBreak);
    return localJSONObject;
  }

  public String getPlotGlyphType()
  {
    return "CustomPlotGlyph";
  }
}